package com.ruoyi.device.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.device.domain.DeviceAccount;
import com.ruoyi.device.service.IDeviceAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备账号信息Controller
 * 
 * @author luogongquan
 * @date 2024-09-06
 */
@RestController
@RequestMapping("/deviceAccount")
public class DeviceAccountController extends BaseController
{
    @Autowired
    private IDeviceAccountService deviceAccountService;

    /**
     * 查询设备账号信息列表
     */
    @RequiresPermissions("device:deviceAccount:list")
    @GetMapping("/list")
    public TableDataInfo list(DeviceAccount deviceAccount)
    {
        startPage();
        List<DeviceAccount> list = deviceAccountService.selectDeviceAccountList(deviceAccount);
        return getDataTable(list);
    }

    /**
     * 导出设备账号信息列表
     */
    @RequiresPermissions("device:deviceAccount:export")
    @Log(title = "设备账号信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceAccount deviceAccount)
    {
        List<DeviceAccount> list = deviceAccountService.selectDeviceAccountList(deviceAccount);
        ExcelUtil<DeviceAccount> util = new ExcelUtil<DeviceAccount>(DeviceAccount.class);
        util.exportExcel(response, list, "设备账号信息数据");
    }

    /**
     * 获取设备账号信息详细信息
     */
    @RequiresPermissions("device:deviceAccount:query")
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
    {
        return success(deviceAccountService.selectDeviceAccountByDeviceId(deviceId));
    }

    /**
     * 新增设备账号信息
     */
    @RequiresPermissions("device:deviceAccount:add")
    @Log(title = "设备账号信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceAccount deviceAccount)
    {
        return toAjax(deviceAccountService.insertDeviceAccount(deviceAccount));
    }

    /**
     * 修改设备账号信息
     */
    @RequiresPermissions("device:deviceAccount:edit")
    @Log(title = "设备账号信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceAccount deviceAccount)
    {
        return toAjax(deviceAccountService.updateDeviceAccount(deviceAccount));
    }

    /**
     * 删除设备账号信息
     */
    @RequiresPermissions("device:deviceAccount:remove")
    @Log(title = "设备账号信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceIds}")
    public AjaxResult remove(@PathVariable Long[] deviceIds)
    {
        return toAjax(deviceAccountService.deleteDeviceAccountByDeviceIds(deviceIds));
    }
}
